package org.itboys.mobile.service.mongo.mobile;

import org.itboys.framework.resource.ResourceHolder;
import org.itboys.mobile.dao.product.SundayProductCategoryMapper;
import org.itboys.mobile.dto.SundayAdvertisementDto;
import org.itboys.mobile.entity.mysql.product.SundayProductCategory;
import org.itboys.mobile.service.mysql.mobile.product.SundayMobileProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：圣代_mobile_综合业务_service
 */
@Service
public class SundayMobileCommonService {
    @Autowired
    private SundayMobileAdvertisementService advertisementService;

    @Autowired
    private SundayProductCategoryMapper productCategoryMapper;
    @Autowired
    private ResourceHolder resourceHolder;
    @Autowired
    private SundayMobileBusinessService businessService;

    /**
     * 获取首页数据。同时记录下用户的经纬度
     * @param memberId
     * @param longitude 当前用户位置经度
     * @param latitude 当前用户位置维度
     * @return
     */
    public Map<String,Object> getIndexData(Long memberId,Double longitude,Double latitude){
        Map<String,Object> result = new HashMap<String,Object>();
        Map<String,Object> param = new HashMap<String,Object>();


        String imgRoot = resourceHolder.getStringValue("imgRoot");
        //首页轮播图
        List<SundayAdvertisementDto> images =advertisementService.getAdvertisementByZone("index_roll");
        result.put("images",images);
        //首页活动
        List<SundayAdvertisementDto> activitys =advertisementService.getAdvertisementByZone("index_activity");
        result.put("activitys",activitys);
        //首页一级分类
        param.clear();
        param.put("parentId",0);
        param.put("sort","sequence");
        param.put("order","asc");
        List<SundayProductCategory>  categoryLists = productCategoryMapper.select(param);
        List<Map<String,Object>> categories =new ArrayList<Map<String, Object>>();
        for(SundayProductCategory categoryList:categoryLists){
            Map<String,Object> category = new HashMap<String,Object>();
            category.put("id",categoryList.getId());
            category.put("name",categoryList.getName());
            category.put("image",imgRoot+categoryList.getImage());
            categories.add(category);
        }
        result.put("categories",categories);
        //获取最近商户
        param.clear();
        /*businessService.getBusiness(null,10,memberId,null);
        result.put("business")*/
        //result.put("products",products);
        return result;
    }


}
